package com;

import cn.hutool.core.util.StrUtil;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class FileTest {

    public static void main(String[] args) {
        Long a=129L;
        Long b=129L;

        System.out.println(a==b);
    }

    public static String download(String downloadUrl, String saveName) {
        String result = "";
        // 下载网络文件
        int bytesum = 0;
        int byteread = 0;
        FileOutputStream fs = null;
        InputStream inStream = null;
        try {
            URL url = new URL(downloadUrl);
            URLConnection conn = url.openConnection();
            inStream = conn.getInputStream();
            String savePath = StrUtil.format("{}/{}", "D:\\", saveName);
            fs = new FileOutputStream(savePath);
            byte[] buffer = new byte[1204];
            int length;
            while ((byteread = inStream.read(buffer)) != -1) {
                fs.write(buffer, 0, byteread);
                bytesum += byteread;
                if (bytesum % (1024 * 1024) < 1000) {
                    System.out.println(Thread.currentThread().getName() + " " + saveName + " 已写入(M) " + (bytesum / 1024 / 1024));
                }
            }
            fs.flush();
            result = StrUtil.format("{}/{}", "D:\\", saveName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

        }
        return result;
    }
}
